package com.example.hxds.dr.controller;

import com.example.hxds.common.dto.RegisterNewDriverDTO;
import com.example.hxds.common.util.MicroAppUtil;
import com.example.hxds.common.util.R;
import com.example.hxds.dr.service.DriverService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/driver")
@Tag(name = "DriverController",description = "后台司机模块接口")
public class DriverController {

    @Autowired
    private DriverService driverService;
    @Autowired
    private MicroAppUtil microAppUtil;

    /*
    * 司机注册接口
    * */
    @PostMapping("/registerNewDriver")
    @Operation(summary = "司机注册")
    public R registerNewDriver(@RequestBody RegisterNewDriverDTO registerNewDriverDTO){
        // 获取微信用户的openId
        String openId = microAppUtil.getOpenId(registerNewDriverDTO.getCode());
        registerNewDriverDTO.setOpenId(openId);
        String driverId = driverService.registerNewDriver(registerNewDriverDTO);
        return R.ok().put("userId",driverId);
    }

}
